extends Area2D
class_name HurtBoxComponent
@export var health_component:HealthComponent

var float_hurt_number = preload("res://Scenes/ui/float_text.tscn")

# 这个组件是用来 收到伤害的
func _ready() -> void:
	area_entered.connect(on_area_enter)
	
func on_area_enter(otherArea: Area2D):
	if not otherArea is HitBoxComponent:
		print("攻击的不是hitbox类型")
		return
	if health_component == null:
		print("没有健康组件")
		return
	var hitbox = otherArea as HitBoxComponent
	health_component.on_damage(hitbox.damage)
	var float_hurt_number_scene = float_hurt_number.instantiate() as Node2D
	get_tree().get_first_node_in_group("foreground_layer").add_child(float_hurt_number_scene)
	float_hurt_number_scene.global_position = global_position
	float_hurt_number_scene.start(str(hitbox.damage))
